package tech.yozo.bamboo;

import android.os.Bundle;
import android.view.Window;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationView;

import androidx.activity.EdgeToEdge;
import androidx.core.splashscreen.SplashScreen;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
import androidx.navigation.fragment.NavHostFragment;
import androidx.navigation.ui.NavigationUI;
import androidx.appcompat.app.AppCompatActivity;

import tech.yozo.bamboo.databinding.ActivityMainBinding;
import tech.yozo.bamboo.ui.reading.ReadingViewModel;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // 初始化额外的界面元素
        initWindow();

        ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment_content_main);
        assert navHostFragment != null;
        NavController navController = navHostFragment.getNavController();

        NavigationView navigationView = binding.navView;
        if (navigationView != null) {
            NavigationUI.setupWithNavController(navigationView, navController);
        }

        BottomNavigationView bottomNavigationView = binding.appContentMain.bottomNavView;
        if (bottomNavigationView != null) {
            NavigationUI.setupWithNavController(bottomNavigationView, navController);
        }

        // 初始化RecognitionViewModel
        ReadingViewModel model =  new ViewModelProvider(this).get(ReadingViewModel.class);
        model.init(this);
    }

    private void initWindow() {
        // 显示启动页
        SplashScreen.installSplashScreen(this);

        // 沉浸式状态栏
        EdgeToEdge.enable(this);

        // 沉浸式导航栏
        Window window = getWindow();
        window.setNavigationBarColor(getColor(R.color.md_theme_surfaceContainer));
    }
}